<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //第一种方案
      function getId() {
        let i = 0
        return i++
      }
      console.log(getId())
      console.log(getId())
      console.log(getId())
      //第二种方法：做到了要求
      //缺点：产生过多的共享变量
      let i
      function getId2() {
        i++
        return i
      }
      console.log(getId2())
      console.log(getId2())
      console.log(getId2())
      i = 1000
      //下面的代码可能出现覆盖geiId2函数
      var getId2 = 'abc'
      getId2()
      //第三种方案：
      let genertora = (function () {
        let i = 1000
        return function () {
          i++
          return i
        }
      })()

      console.log(genertora())
    </script>
  </body>
</html>
